<?php
/**
 * 双色球奖金计算.
 * ?num=3,21,6,13,14,17,2
 * 传入7个彩票数子
 * {
"code": 200,
"msg": "开奖结果",
"list": {
"type": 5,
"typenum": "1287687",
"typemoney": "10"
}
}
 * User: Yoby logove@qq.com
 * Date: 2019/5/19 18:36
 * wechat: logove
 */
if (!function_exists('dump')) {
    function dump($arr){
        echo '<pre>'.print_r($arr,TRUE).'</pre>';
    }

}
function curl($url,$data = ''){
    $ch = curl_init();
    if (class_exists('\CURLFile'))
    {
        curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
    }
    else
    {
        if (defined('CURLOPT_SAFE_UPLOAD'))
        {
            curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
        }
    }
    preg_match('/https:\/\//', $url) ? $ssl = TRUE : $ssl = FALSE;
    if ($ssl) {
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    }
    curl_setopt($ch, CURLOPT_URL, $url);
    if (!empty($data))
    {
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $d = curl_exec($ch);
    curl_close($ch);
    return $d;
}
function get_current_url(){
    $current_url='http://';
    if(isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']=='on'){
        $current_url='https://';
    }
    if($_SERVER['SERVER_PORT']!='80'){
        $current_url.=$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'];
    }else{
        $current_url.=$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
    }
    return $current_url;
}
/*返回ajax状态*/
function json($code=200,$message='请求成功',$list=array(),$total=0){
    $json = array(
        'code'=>$code,
        'msg'=>$message
    );
    if(!empty($list)){
        $json['list'] = $list;
    }
    if(!empty($total)){
        $json['total'] = $total;
    }

    header('Content-type: application/json');
    exit(json_encode($json,JSON_UNESCAPED_UNICODE));
}
//13,14,17,19,21,29 01
if(empty($_GET['num'])){
  json(0,"彩票不能为空");
}else{
    $str =trim($_GET['num']);
}


$arr = json_decode(curl(dirname(get_current_url())."/fucai_api.php"),1);
$arr = $arr['result'][0];

$red = $arr['red'];//中将红球字符串
$redarr = explode(',',$red);//开奖结果

$blue = $arr['blue'];//中奖篮球



$rank = $arr['prizegrades'];//中奖等级 0为1等奖


$redarr1 = explode(',',$str);//购买的彩票

if(count($redarr1)!=7){
    json(0,"彩票必须七个数字");
}

$s7 = $redarr1[6];
array_pop($redarr1);//去掉最后一个

$blue1=$s7;




$rednum=0;$bluenum=0;
$d=7;
for($i=0;$i<6;$i++){
    if(in_array($redarr1[$i],$redarr)){
        $rednum++;
    }
}
    if($blue==$blue1){
        $bluenum=1;
    }

if($rednum<3 && $bluenum==1){
    $d=6;
}elseif(($rednum==4 && $bluenum==0) || ($rednum==3 && $bluenum==1) ){
$d = 5;
}elseif(($rednum==5 && $bluenum==0) || ($rednum==4 && $bluenum==1) ){
$d=4;
}elseif($rednum==5 && $bluenum==1 ){
$d=3;
}elseif($rednum==6){
 $d=2;
}elseif($rednum==6 && $bluenum==1){
  $d=1;
}
json(200,'开奖结果',$rank[$d-1]);

